﻿var servicevalues = new Array() ;
var servicenames = new Array();
// get html insert update delete
function gethtml(address)
{
   var options = setDichVu();
    var html = "<table width='100%' border='0'>" +
      "<tr> <td width='35%'>Địa Điểm </td>" +
    " <td width='65%'> <input type='text' id='name'/> </td>  </tr>" + 
    "<tr> <td>Địa Chỉ</td><td> <input type='text' value='" + address + "' id='address'/></td>" + 
    "</tr> <tr> <td>Miêu Tả </td> <td> <input type='text' id='description' /></td>" + 
    "</tr><tr><td>Dịch Vụ</td><td><form id='form1' name='form1' method='post' action=''>"+
    "<label> <select id='type'>" + options
    
    + "</select></label> </form></td> </tr> <tr>" + 
    "<td></td>" +
    "<td><input name='Thêm' type='button' value='Thêm' onclick='saveData()' />" +
    "</td></tr></table>";
    
    return html;
}
function gethtmlUpdate(id ,name, address, desciption,lat, lng)
{
    var options = setDichVu();
    var html = "<table width='100%' border='0'> " +
    "<tr> <td width='35%'><input type='hidden' value='"+ id +"' id='addressid' />" +
    "<input type='hidden' value='"+ lat +"' id='lat' />" +
    "<input type='hidden' value='"+ lng +"' id='lng' />Địa Điểm </td>" +
    " <td width='65%'> <input type='text' value='" + name + "'id='name'/> </td>  </tr>" + 
    "<tr> <td>Địa Chỉ</td><td> <input type='text' value='" + address + "' id='address'/></td>" + 
    "</tr> <tr> <td>Miêu Tả </td> <td> <input type='text'  value='"+ desciption +"' id='description' /></td>" + 
    "</tr><tr><td>Dịch Vụ</td><td><form id='form1' name='form1' method='post' action=''>"+
    "<label> <select id='type'>" + options
    
    + "</select></label> </form></td> </tr> <tr>" + 
    "<td><a href='ManagerMap.aspx?action=Xoa'  onclick='deleteData()'>Xóa</a></td><td>" +
    "<input name='Cập Nhập' type='button' value='Sữa' onclick='updateData()'/> </td></tr></table>";
    
    return html;
}

function setDichVu(){
    servicevalues = new Array();
    servicenames = new Array();
    servicevalues.push(1);
    servicenames.push("Trường Học");
    servicevalues.push(2);
    servicenames.push("Quán Ăn");
    servicevalues.push(3);
    servicenames.push("Quán Cafe"); 
    servicevalues.push(4);
    servicenames.push("Khách sạn"); 
    servicevalues.push(5);
    servicenames.push("Công Viên"); 
    servicevalues.push(6);
    servicenames.push("Ngân Hàng");     
     
    var options = "";
    for(var i = 0; i< servicevalues.length; i++){
        options = options + '<option value="' +servicevalues[i]+ '">' + servicenames[i] + '</option>';
    }   
    return options;
   
}

 function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var description = escape(document.getElementById("description").value);
      var type = document.getElementById("type").value;
      var latlng = markerInsert.getPosition();
    
      var url = "ManagerMap.aspx?action=Them&name=" + name + "&address=" + address + 
                 "&description=" + description + "&type=" + type +
                 "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200) {
          infoWindowInsert.close();
          alert("Thêm Thành Công");         
        }
      });
    }
 function saveDatas() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var description = escape(document.getElementById("description").value);
      var type = document.getElementById("type").value;
      var lat = parseFloat(document.getElementById("lat").value);
      var lng = parseFloat(document.getElementById("lng").value);
    
      var url = "ManagerMap.aspx?action=Them&name=" + name + "&address=" + address + 
                 "&description=" + description + "&type=" + type +
                 "&lat=" + lat + "&lng=" + lng;
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200) {
          infoWindowInsert.close();
          alert("Thêm Thành Công");         
        }
      });
    }
  function updateData() {
       var id = document.getElementById("addressid").value;
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var description = escape(document.getElementById("description").value);
      var type = document.getElementById("type").value;
      var lat = parseFloat(document.getElementById("lat").value);
      var lng = parseFloat(document.getElementById("lng").value);
    
      var url = "ManagerMap.aspx?action=Sua&id=" + id + "&name=" + name + "&address=" + address + 
                 "&description=" + description + "&type=" + type +
                 "&lat=" + lat + "&lng=" + lng;
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200) {          
          alert("Cập Nhập Thành Công");         
        }
      });
    }
  function deleteData() {
       var id = document.getElementById("addressid").value;
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var description = escape(document.getElementById("description").value);
      var type = document.getElementById("type").value;
      var lat = parseFloat(document.getElementById("lat").value);
      var lng = parseFloat(document.getElementById("lng").value);
    
      var url = "ManagerMap.aspx?action=Xoa&id=" + id + "&name=" + name + "&address=" + address + 
                 "&description=" + description + "&type=" + type +
                 "&lat=" + lat + "&lng=" + lng;
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200) {          
          alert("Xóa Thành Công");         
        }
      });
    }